home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / util / moni / Scout-src.lha / source / objects / scout_asm.asm < prev    next >
Encoding:
Assembly Source File  |  2002-09-17  |  12.4 KB  |  594 lines

  1. **
  2. * Scout - The Amiga System Monitor
  3. *
  4. *------------------------------------------------------------------
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. *
  20. * You must not use this source code to gain profit of any kind!
  21. *
  22. *------------------------------------------------------------------
  23. *
  24. * @author Andreas Gelhausen
  25. * @author Richard Körber <rkoerber@gmx.de>
  26. *
  27.  
  28.  
  29.  
  30.         include "objects/scout_asm.i"
  31.         include "exec/funcdef.i"
  32.         include "exec/exec_lib.i"
  33.         include "lvo/mmu_lvo.i"
  34.  
  35.         SECTION CODE
  36.  
  37.         xdef _MyCause
  38. _MyCause:
  39.         ;=================================
  40.         ; causes software interrupt
  41.         ;=================================
  42.         ;  > A0: Passed to SoftInt
  43.         ;  > A1: Int-Structure
  44.         ;  < D0: Return Code
  45.         movem.l a0-a6/d1-d7,-(sp)
  46.         move.l  $4.w,a6
  47.         move.l  IS_DATA(a1),a1
  48.         move.l  IS_CODE(a1),a2
  49.         jsr     (a2)
  50.         movem.l (sp)+,a0-a6/d1-d7
  51.         rts
  52.  
  53.  
  54.         xdef _NameCopy
  55. _NameCopy:
  56.         ;=================================
  57.         ;copy name (e.g. "euro72.monitor") to buffer, until '.' or null termination
  58.         ;  (also uppercase)
  59.         ;=================================
  60.         ;  > A0: ^Target
  61.         ;  > A1: ^Source
  62.         movem.l a0/a1,-(sp)
  63. copy_loop:
  64.         move.b  (a1)+,d0
  65.         beq     copy_done
  66.         cmp.b   #'.',d0
  67.         beq     copy_done
  68.         cmp.b   #'a',d0                 ;Upper Case
  69.         bcs     copy_ok
  70.         cmp.b   #'z',d0
  71.         bhi     copy_ok
  72.         sub.b   #32,d0
  73. copy_ok:
  74.         move.b  d0,(a0)+
  75.         bra     copy_loop
  76. copy_done:
  77.         move.b  #':',(a0)+
  78.         clr.b   (a0)+
  79.         movem.l (sp)+,a0/a1
  80.         rts
  81.  
  82.  
  83.  
  84.         xdef _GetCACR
  85. _GetCACR:
  86.         ;=================================
  87.         ;return current value of CACR in d0
  88.         ;=================================
  89.  
  90.         movem.l a5/a6,-(SP)
  91.         moveq.l #0,d0
  92.         move.l  _AbsExecBase,a6
  93.         move.w  AttnFlags(a6),d1
  94.         btst    #AFB_68020,d1
  95.         beq.s   _GetCACR_Exit
  96.  
  97.         lea     CACR_to_d0(PC),a5
  98.         jsr     _LVOSupervisor(a6)
  99. _GetCACR_Exit:
  100.         movem.l (SP)+,a5/a6
  101.         rts
  102.  
  103. CACR_to_d0:
  104.         movec.l CACR,D0
  105.         rte
  106.  
  107.  
  108.         xdef _GetPCR
  109. _GetPCR:
  110.         ;=================================
  111.         ;return current value of PCR in d0
  112.         ;=================================
  113.  
  114.         movem.l a5/a6,-(SP)
  115.         moveq.l #0,d0
  116.         move.l  _AbsExecBase,a6
  117.         move.w  AttnFlags(a6),d1
  118.         btst    #AFB_68060,d1
  119.         beq.s   _GetPCR_Exit
  120.  
  121.         lea     PCR_to_d0(PC),a5
  122.         jsr     _LVOSupervisor(a6)
  123. _GetPCR_Exit:
  124.         movem.l (SP)+,a5/a6
  125.         rts
  126.  
  127. PCR_to_d0:
  128.         dc.w    $4E7A,$0808             ; movec.l PCR,D0
  129.         rte
  130.  
  131.  
  132.  
  133.         xdef _GetVBR
  134.  
  135. _GetVBR:
  136.         ;=================================
  137.         ;return current value of VBR in d0
  138.         ;=================================
  139.  
  140.         movem.l a5/a6,-(SP)
  141.         moveq.l  #0,d0
  142.         move.l  _AbsExecBase,a6
  143.         move.w  AttnFlags(a6),d1
  144.         btst    #AFB_68010,d1
  145.         beq.s    _GetVBR_Exit
  146.  
  147.         lea        VBR_to_d0(PC),a5
  148.         jsr        _LVOSupervisor(a6)
  149.  
  150. _GetVBR_Exit:
  151.    movem.l      (SP)+,a5/a6
  152.         rts
  153.  
  154. VBR_to_d0:
  155.         movec.l VBR,D0
  156.         rte
  157.  
  158.  
  159.         xdef _SetVBR
  160.  
  161. _SetVBR:
  162.         ;=========================
  163.         ;move Value from a0 to VBR
  164.         ;=========================
  165.         movem.l a5/a6,-(SP)
  166.         move.l  _AbsExecBase,a6
  167.         move.w  AttnFlags(a6),d0
  168.         btst    #AFB_68010,d0
  169.         beq.s    _SetVBR_Exit
  170.  
  171.         move.l  a0,d0                   ; We pass the new VBR in a0, because
  172.                                                 ; it is a pointer (and pointers are
  173.                                                  ; put in address registers).
  174.         lea        d0_to_VBR(PC),a5
  175.         jsr        _LVOSupervisor(a6)
  176.  
  177. _SetVBR_Exit:
  178.         movem.l (SP)+,a5/a6
  179.         rts
  180.  
  181. d0_to_VBR:
  182.         movec.l D0,VBR
  183.         rte
  184.  
  185.         xdef _ReadZeroPage
  186.         xref _MMUBase
  187.  
  188. _ReadZeroPage:
  189.         movem.l a5-a6,-(sp)
  190.         move.l  _MMUBase,a6
  191.         lea     _ReadPage(pc),a5
  192.         jsr     _LVOWithoutMMU(a6)
  193.         move.l  d0,(a1)
  194.         move.l  d1,(a2)
  195.         movem.l (sp)+,a5-a6
  196.         rts
  197.  
  198. _ReadPage:
  199.         move.l  $100(a0),d0
  200.         move.l  $104(a0),d1
  201.         rts
  202.  
  203.  
  204.    xdef _SetPatches
  205.    xref _AbsExecBase
  206.  
  207. _SetPatches:
  208.         ;=================================
  209.         ;set patch for task switching
  210.         ;=================================
  211.    movem.l  d0-d4/a0-a6,-(sp)
  212.    move.l   _AbsExecBase,a6
  213.    jsr      _LVOForbid(a6)
  214.  
  215.    move.l   _CodeAddress,a5
  216.  
  217.    move.w   #-54,d0
  218.    lea      (a5),a0
  219.    exg.l    d0,a0
  220.    move.l   a6,a1
  221.    jsr      _LVOSetFunction(a6)
  222. ;   lea      _OldSwitch(pc),a0
  223. ;   move.l   d0,(a0)
  224.  
  225.    move.w   #_LVOAddTask,d0
  226.    lea      _MyAdd-_MySwitch(a5),a0
  227.    exg.l    d0,a0
  228.    move.l   a6,a1
  229.    jsr      _LVOSetFunction(a6)
  230. ;   lea      _OldAddTask(pc),a0
  231. ;   move.l   d0,(a0)
  232.  
  233.    jsr      _LVOPermit(a6)
  234.    movem.l  (sp)+,d0-d4/a0-a6
  235.    rts
  236.  
  237.  
  238. _TaskNumber    EQU 128
  239. _LVOAddTime    EQU -42
  240. _LVOSubTime    EQU -48
  241. _LVOCmpTime    EQU -54
  242. _LVOReadEClock EQU -60
  243. _LVOGetSysTime EQU -66
  244. ;-----------------------------------------------------------------
  245. ; Die hier folgenden Routinen werden vor der Installierung der
  246. ;  Patches kopiert!  (bis einschließlich _CodeAddress)
  247. ;-----------------------------------------------------------------
  248.  
  249.         xdef _MySwitch
  250.  
  251. _MySwitch:
  252.         ;=================================
  253.         ;patch routine for task switching
  254.         ;=================================
  255.    movem.l  d0/a0,-(sp)
  256.    move.b   _SwitchState(pc),d0
  257.    beq      _OldSwitchFunc
  258.  
  259. swstart:
  260.    movem.l  d1-d3/a1-a4/a6,-(sp)
  261.    lea      _OldTimeVal(pc),a4
  262.    move.l   _MyTVSecs(pc),(a4)+
  263.    move.l   _MyTVMicro(pc),(a4)
  264.  
  265.    move.l   _AsmTimerBase(pc),a6
  266.    lea      _MyTimeVal(pc),a0
  267.    jsr      _LVOGetSysTime(a6)
  268.  
  269.    cmp.l    #42,-(a4)
  270.    beq.s    swexit
  271.  
  272.    lea      _MyTimeVal(pc),a0
  273.    lea      _OldTimeVal(pc),a1
  274.    jsr      _LVOSubTime(a6)
  275.  
  276.    move.l   _AbsExecBase,a6
  277.    move.l   ThisTask(a6),d0
  278.  
  279.    move.l   _TaskPtr1(pc),a4
  280.    move.l   #_TaskNumber-1,d3
  281. swloop:
  282.    move.l   (a4),d1
  283.    cmp.l    d0,d1
  284.    beq.s    swfound
  285.    lea      8(a4),a4
  286.    dbf      d3,swloop
  287.  
  288.    move.l   _TaskPtr1(pc),a4
  289.    move.l   #_TaskNumber-1,d3
  290. swloop2:
  291.    move.l   (a4),d1
  292.    beq.s    swfound     ;Task noch nicht in der Tabelle
  293.    lea      8(a4),a4
  294.    dbf      d3,swloop2
  295.    bra.s    swexit      ;Task konnte nicht mehr in die Tabelle
  296.                         ; aufgenommen werden
  297.  
  298. swfound:
  299.    move.l   d0,(a4)
  300.    move.l   _MyTVMicro(pc),d0
  301.    add.l    d0,4(a4)
  302.    lea      _TotalMicros1(pc),a0
  303.    add.l    d0,(a0)
  304.    bra.s    swexit
  305. swnext:
  306.    lea      8(a4),a4
  307.    dbf      d3,swloop
  308.  
  309. swexit:
  310.    lea      _TotalMicros1(pc),a0
  311.    move.l   (a0),d0
  312.    andi.l   #$ff000000,d0
  313.    tst.l    d0
  314.    beq.s    swnoshift
  315.    lsr.l    #8,d0
  316.    lsr.l    #4,d0
  317.    move.l   d0,(a0)
  318.  
  319.    move.l   _TaskPtr1(pc),a4
  320.    move.l   #_TaskNumber-1,d3
  321. swshift:
  322.    cmp.l    #-2,(a4)
  323.    beq.s    swshiftnext
  324.  
  325.    move.l   4(a4),d0
  326.    lsr.l    #8,d0
  327.    lsr.l    #4,d0
  328.    move.l   d0,4(a4)
  329. swshiftnext:
  330.    lea      8(a4),a4
  331.    dbf      d3,swshift
  332.  
  333. swnoshift:
  334.    move.l   _AsmTimerBase(pc),a6
  335.    lea      _MyTimeVal(pc),a0
  336.    jsr      _LVOGetSysTime(a6)
  337.    movem.l  (sp)+,d1-d3/a1-a4/a6
  338.  
  339. _OldSwitchFunc:
  340.    movem.l  (sp)+,d0/a0
  341.    move.l   _OldSwitch(pc),-(sp)
  342.    rts
  343.  
  344.  
  345. _MyTimeVal:
  346. _MyTVSecs:     dc.l  42
  347. _MyTVMicro:    dc.l  0
  348.  
  349. _OldTimeVal:
  350. _OldTVSecs:    dc.l  0
  351. _OldTVMicro:   dc.l  0
  352.  
  353.  
  354.    xdef _SwitchState
  355.  
  356. _SwitchState:  dc.b  0,0
  357.  
  358.  
  359.         xdef _MyAdd
  360.  
  361. _MyAdd:
  362.         ;=================================
  363.         ;patch routine for task adding
  364.         ;=================================
  365. addstart:
  366.    movem.l  d1/d4/d6/a0/a4/a6,-(sp)
  367.    move.l   a1,d4
  368.    bsr.s    _OldAddTaskFunc
  369.  
  370.    move.b   _SwitchState(pc),d1
  371.    beq.s    addexit
  372.  
  373. ;   move.l   _AbsExecBase,a6
  374. ;   jsr      _LVOForbid(a6)   ;Darf nicht verwendet werden! (Absturz)
  375.  
  376.    move.l   _TaskPtr1(pc),a4
  377.    move.l   #_TaskNumber-1,d6
  378. addloop:
  379.    move.l   (a4),d1
  380.    bne.s    addnext
  381.  
  382. addfound:
  383.    move.l   #-2,(a4)    ;added task = -2 
  384.    move.l   d4,4(a4)    ;task address
  385.    bra.s    addexit
  386. addnext:
  387.    lea      8(a4),a4
  388.    dbf      d6,addloop
  389.  
  390. addexit:
  391. ;   jsr      _LVOPermit(a6)
  392.    movem.l  (sp)+,d1/d4/d6/a0/a4/a6
  393.    rts
  394.  
  395. _OldAddTaskFunc:
  396.    move.l   _OldAddTask(pc),-(sp)
  397.    rts
  398.  
  399.  
  400.         xdef _ClearTaskData
  401.  
  402. ;-------------------------------------------------------------------
  403. ; Die Routine 'ClearTaskData' muß vor der Installierung der Patches
  404. ; aufgerufen werden!
  405. ;-------------------------------------------------------------------
  406.  
  407. _ClearTaskData:
  408.    movem.l  d0-d3/a0-a4/a6,-(sp)
  409.    move.b   _TaskPtrState(pc),d0
  410.    bne.s    ctstart
  411.  
  412.    lea      _TaskPtr1(pc),a4
  413.    jsr      _AllocTaskBuffer
  414.  
  415. ctstart:
  416.    move.l   _AbsExecBase,a6
  417.    jsr      _LVOForbid(a6)
  418.  
  419.    lea      _TaskPtr1(pc),a4     ;Pointer austauschen!
  420.    move.l   (a4),d0
  421.    move.l   4(a4),(a4)
  422.    move.l   d0,4(a4)
  423.  
  424.    lea      _TotalMicros1(pc),a4 ;TotalMicros austauschen!
  425.    move.l   (a4),d0
  426.    move.l   4(a4),(a4)
  427.    move.l   d0,4(a4)
  428.  
  429.    jsr      _LVOPermit(a6)
  430.  
  431.    moveq    #0,d0
  432.    move.l   _TaskPtr1(pc),a0
  433.    move.l   #_TaskNumber*2-1,d1
  434. ctloop:
  435.    move.l   d0,(a0)+
  436.    dbf      d1,ctloop
  437.  
  438.    lea      _TotalMicros1(pc),a0
  439.    move.l   #0,(a0)
  440.  
  441. ctexit:
  442.    movem.l  (sp)+,d0-d3/a0-a4/a6
  443.    rts
  444.  
  445.  
  446.         xdef _GetTaskData
  447.  
  448. _GetTaskData:
  449.    movem.l  d1-d3/a0,-(sp)
  450.    move.l   d0,d2
  451.  
  452.    move.l   _TaskPtr2(pc),a0
  453.    move.l   #_TaskNumber-1,d3
  454.    moveq    #0,d0
  455. gtloop:
  456.    move.l   (a0),d1
  457.    cmp.l    d1,d2
  458.    bne.s    gtnext
  459.    move.l   4(a0),d0
  460. ;   move.l   d0,d1
  461. ;   lsl.l    #3,d1
  462. ;   lsl.l    #1,d0
  463. ;   add.l    d1,d0
  464.    bra.s    gtexit
  465. gtnext:
  466.    lea      8(a0),a0
  467.    dbf      d3,gtloop
  468. gtexit:
  469.    movem.l  (sp)+,d1-d3/a0
  470.    rts
  471.  
  472. _TaskPtr1:    dc.l  0     ;Die Reihenfolge dieser drei
  473. _TaskPtr2:    dc.l  0     ; Variablen unbedingt so lassen!
  474. _TaskPtrState: dc.b  0,0
  475.  
  476.  
  477.    xdef _TotalMicros1
  478.  
  479. _TotalMicros1: dc.l  0
  480. _TotalMicros2: dc.l  0
  481.  
  482.  
  483.    xdef _OldSwitch
  484.  
  485. _OldSwitch:    dc.l  0
  486.  
  487.  
  488.    xdef _OldAddTask
  489.  
  490. _OldAddTask:    dc.l  0
  491.  
  492.  
  493.         xdef _GetAddedTask
  494.  
  495. _GetAddedTask:
  496.    movem.l  d1/d6/a4,-(sp)
  497.    move.l   _TaskPtr2(pc),a4
  498.    move.l   #_TaskNumber-1,d6
  499.    moveq    #0,d0
  500.    move.l   #-2,d1
  501. galoop:
  502.    cmp.l    (a4),d1
  503.    bne.s    ganext
  504.  
  505. gafound:
  506.    move.l   4(a4),d0
  507.    move.l   #0,(a4)
  508.    move.l   #0,4(a4)
  509.    bra.s    gaexit
  510. ganext:
  511.    lea      8(a4),a4
  512.    dbf      d6,galoop
  513.  
  514. gaexit:
  515.    movem.l  (sp)+,d1/d6/a4
  516.    rts
  517.  
  518.  
  519.    xdef _AsmTimerBase
  520.  
  521. _AsmTimerBase:
  522.     dc.l  0
  523.  
  524.  
  525.    xdef _CodeAddress
  526.  
  527. _CodeAddress:
  528.     dc.l  0
  529.  
  530. ;-----------------------------------------------------------------
  531. ; Ab hier kommen Dinge, die nicht für die Patches kopiert werden!
  532. ;-----------------------------------------------------------------
  533.  
  534. _AllocTaskBuffer:          ;a4: Adresse von TaskPtr1
  535.    movem.l  d0-d4/a4/a6,-(sp)
  536.    move.l   _AbsExecBase,a6
  537.    move.l   #_TaskNumber*16+8,d0
  538.    move.l   #$10001,d1
  539.    jsr      _LVOAllocMem(a6)
  540.    move.l   d0,d4
  541.    beq.s    atbx
  542.  
  543.    jsr      _LVOForbid(a6)
  544.  
  545.    move.l   #_TaskNumber*16+8,d0
  546.    move.l   d4,a1
  547.    jsr      _LVOFreeMem(a6)
  548.  
  549.    move.l   #_TaskNumber*8+4,d0
  550.    move.l   #$50001,d1
  551.    jsr      _LVOAllocMem(a6)
  552.    move.l   d0,(a4)
  553.    beq.s    atbx
  554.  
  555.    move.l   #_TaskNumber*8+4,d0
  556.    move.l   #$50001,d1
  557.    jsr      _LVOAllocMem(a6)
  558.    move.l   d0,4(a4)
  559.    beq.s    ftb1
  560.    move.b   #1,8(a4)
  561. atbx:
  562.    jsr      _LVOPermit(a6)
  563.    movem.l  (sp)+,d0-d4/a4/a6
  564.    rts
  565.  
  566.  
  567. ;_FreeTaskBuffer:
  568. ;   movem.l  d0-d4/a4/a6,-(sp)
  569. ;   move.l   _AbsExecBase,a6
  570. ;;   jsr      _LVOForbid(a6)
  571. ;
  572. ;   lea      _TaskPtr1(pc),a4
  573. ;   move.l   _TaskPtr2(pc),d0
  574. ;   beq.s    ftb1
  575. ;   move.l   #_TaskNumber*8,a1
  576. ;   exg.l    d0,a1
  577. ;   jsr      _LVOFreeMem(a6)
  578. ;   clr.l    4(a4)
  579. ftb1:
  580.    move.l   _TaskPtr1(pc),d0
  581.    beq.s    ftbx
  582.    move.l   #_TaskNumber*8+4,a1
  583.    exg.l    d0,a1
  584.    jsr      _LVOFreeMem(a6)
  585.    clr.l    (a4)
  586.    move.b   #0,8(a4)
  587. ftbx:
  588.    jsr      _LVOPermit(a6)
  589.    movem.l  (sp)+,d0-d4/a4/a6
  590.    rts
  591.  
  592.  
  593.         END
  594.